package com.tinyengine.it.service.engine.extend.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tinyengine.it.mapper.TUserMapper;
import com.tinyengine.it.model.entity.TUser;
import com.tinyengine.it.service.engine.extend.TUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

/**
 * @author Administrator
 * @description 针对表【t_user(用户表)】的数据库操作Service实现
 * @createDate 2025-04-29 08:52:14
 */
@Service
@RequiredArgsConstructor
public class TUserServiceImpl extends ServiceImpl<TUserMapper, TUser>
        implements TUserService {

    private final PasswordEncoder passwordEncoder;

    @Override
    public TUser findByUsername(String username) {
        return baseMapper.selectOne(new LambdaQueryWrapper<TUser>().eq(TUser::getUsername, username));
    }

    @Override
    public void createUser(String username, String password, String email) {
        TUser user = new TUser();
        user.setUsername(username);
        user.setPassword(passwordEncoder.encode(password));
        user.setEmail(email);
        //user.setStatus(1);
        //user.setCreateTime(LocalDateTime.now());
        user.setCreatedBy("admin");
        user.setLastUpdatedBy("admin");
        baseMapper.insert(user);
    }

}




